package com.wjgl.service;

import java.util.List;

import com.wjgl.dao.InstitutionDAO;
import com.wjgl.domain.Institution;

public class InstitutionService {
	private InstitutionDAO institutionDAO;

	public void setInstitutionDAO(InstitutionDAO institutionDAO) {
		this.institutionDAO = institutionDAO;
	} 
	
	public List<Institution> getAllInstitutions(){
		return (List<Institution>)institutionDAO.findAll();
	}
	
	public boolean lockInstitution(int id){
		boolean b = false;
		Institution ins = institutionDAO.findById(id);
		if(ins != null){
			ins.setState((short)2);
			institutionDAO.update(ins);
			b = true;
		}
		return b;
	}
	
	public boolean unlockInstitution(int id){
		boolean b = false;
		Institution ins = institutionDAO.findById(id);
		if(ins != null){
			ins.setState((short)1);
			institutionDAO.update(ins);
			b = true;
		}
		return b;
	}
	
	public boolean deleteInstitution(int id){
		boolean b = false;
		Institution ins = institutionDAO.findById(id);
		if(ins != null){
			institutionDAO.delete(ins);
			b = true;
		}
		return b;
	}
	
	public void addInstitution(Institution ins){
		institutionDAO.save(ins);
	}
	
	public Institution findInstitutionById(int id){
		return institutionDAO.findById(id);
	}
	
	public void updateInstitution(Institution ins){
		institutionDAO.update(ins);
	}
	
}
